package com.wz.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wz.common.utils.text.Convert;
import com.wz.device.entity.BasDevice;
import com.wz.device.mapper.BasDeviceMapper;
import com.wz.device.service.BasDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Service
public class BasDeviceServiceImpl extends ServiceImpl<BasDeviceMapper, BasDevice> implements BasDeviceService {


    @Autowired
    private BasDeviceMapper basDeviceMapper;

    /**
     *  根据条件分页查询设备库房列表
     *
     * @param basDevice 设备库域信息
     * @return
     */
    @Override
    public List<BasDevice> selectBasDeviceList(BasDevice basDevice) {
        // 生成数据权限过滤条件
        return basDeviceMapper.selectBasDeviceList(basDevice);
    }

    /**
     * 新增设备信息
     * @param basDevice 设备信息
     * @return
     */
    @Override
    public int insertBasDevice(BasDevice basDevice) {
        // 新增设备信息
        int rows = 0;
        try {
            rows = basDeviceMapper.insertBasDevice(basDevice);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rows;
    }


    /**
     * 根据设备ID查询设备
     * @param device_id 设备ID
     * @return
     */
    @Override
    public BasDevice selectBasDevice(String device_id) {
        return basDeviceMapper.selectBasDeviceById(device_id);
    }

    /**
     * 更新设备信息
     * @param basDevice 设备信息
     * @return
     */
    @Override
    public int updateBasDevice(BasDevice basDevice) {
        try {
            return basDeviceMapper.updateBasDevice(basDevice);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 根据设备ID删除设备信息
     * @param ids 需要删除的数据ID
     * @return
     */
    @Override
    public int deleteDeviceByIds(String ids) {
        try {
            String[] deviceIds = Convert.toStrArray(ids);
            return basDeviceMapper.deleteDeviceByIds(deviceIds);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 更改设备是否锁定
     * @param basDevice 设备信息
     * @return
     */
    @Override
    public int changeLocked(BasDevice basDevice) {
        try {
            return basDeviceMapper.updateBasDevice(basDevice);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }


}
